<template>
  <div class="nsw-container">
    <el-row>
      <div class="login-container">
        <div class="right-item">
          <img src="@/assets/logo/logo2.png" alt="logo" />
        </div>
        <div class="left-item">
          <div class="signin-wrap">
            <div class="signin-wrap-title">登录</div>
            <div class="signin-form-main">
              <div class="signin-form">
                <el-form
                    :model="userForm"
                    status-icon
                    :rules="rules"
                    ref="userForm"
                    label-width="80px"
                    class="demo-ruleForm"
                    hide-required-asterisk
                >
                  <el-form-item label="用户名" prop="username">
                    <el-input
                        type="account"
                        v-model="userForm.username"
                        placeholder="请输入用户名"
                        autocomplete="off"
                    ></el-input>
                  </el-form-item>
                  <el-form-item label="密码" prop="password">
                    <el-input
                        type="password"
                        v-model="userForm.password"
                        placeholder="请输入密码"
                        autocomplete="off"
                    ></el-input>
                  </el-form-item>
                  <el-form-item>
                    <el-button
                        type="primary"
                        :loading="loading"
                        @click="submitForm"
                        class="submit-btn"
                    >登录</el-button>
                  </el-form-item>
                </el-form>
              </div>
            </div>
        </div>
        </div>
      </div>
    </el-row>
  </div>
</template>

<script>
export default {
  name: "Login",
  data(){
    return {
      userForm: {
        username: "",
        password: "",
      },
      rules: {
        username: [{ required: true, trigger: "blur", message: "请输入用户名" }],
        password: [{ required: true, trigger: "blur", message: "请输入密码" }],
      },
      loading: false,
      isShow: 1,
    }
  },
  methods: {
    submitForm() {
      this.$refs['userForm'].validate((valid) => {
        if (valid) {
          this.loading = true;
          this.$store.dispatch("Login", this.userForm).then(() => {
            this.$router.push({ path: this.redirect || "/index" }).catch(()=>{});
          }).catch(() => {
            this.loading = false;
          });
        } else {
          return false;
        }
      });
    },
    changeIsShow(n) {
      this.isShow = n;
    },
  },
}
</script>

<style scoped lang="scss">
.login-container {
  width: 100%;
  height: calc(100vh - 270px);
  margin: 1px 0px;
  background-image: url("~@/assets/success-case/4.jpg") ;
  display: flex;
  justify-content: space-around;
  align-items: center;
.right-item {
  img {
    width: 450px;
  }
  }
}
.left-item{
  a {
    color: black;
    text-decoration: none;
  }
  .signin-wrap {
    // height: 370px;
    width: 500px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    background-color: rgba(255, 255, 255, 0.5);
    border-radius: 20px;
  }
  .signin-wrap-title{
    text-align: center;
    font-size: 26px;
    font-weight: bold;
  }
  /* 主体 */
  .signin-form-main {
    padding: 5px 20px;
  }
  .signin-form {
    width: 100%;
  }
  /* foot */
  .signin-operate {
    line-height: 15px;
    padding: 10px 0 10px 15px;;
    margin: 0px 20px;
    display: flex;
    align-items: center;
    font: {
      size: 14px;
      weight: bolder;
    }
  }
  ::v-deep .el-divider {
    background-color: black;
  }
}
</style>
